from django.utils.six import BytesIO
from rest_framework.parsers import JSONParser

from api.tests.base_test_case import BaseTestCase
from app.models.pay_method import PayMethod


class PayMethodTest(BaseTestCase):
    def setUp(self):
        super(PayMethodTest, self).setUp()
        self.pay_method1 = PayMethod.objects.create(name='货到付款', enabled=True, priority=1)
        self.pay_method2 = PayMethod.objects.create(name='在线付款', enabled=True, priority=2)

    def test_get_pay_methods(self):
        r = self.client.get('/api/pay-method/',
                            accept_media_type='application/json')
        self.assertEqual(r.status_code, 200)
        pay_method_list = JSONParser().parse(BytesIO(r.content))
        self.assertEqual(len(pay_method_list), 2)
